home *** CD-ROM | disk | FTP | other *** search
- ; RUN THIS FROM THE CLI ONCE COMPILED
- ; Run the other program before this one from the CLI, i.e.
- ; 1> run prog_a <RETURN>
- ; 1> run prog_b <RETURN>
-
- ; You will need blitzlibs:amigalibs.res resident
- ; **********************************************
-
- ; This program finds the message port created by the other program,
- ; sends it a message then waits for the reply.
-
- ; Needs to be same type of structure as the other program
- NEWTYPE.NrMessage
- SystemMsg.Message
- number.w
- End NEWTYPE
-
- ; Declare a pointer to the public message port and our reply port
- DEFTYPE.MsgPort *msgp, *replymsgp
-
- ; Declare a pointer to a message
- DEFTYPE.NrMessage *nrmsg, *msg
-
- ; Start of main program
- ; Allocate some memory for message (public memory and clear)
- *nrmsg = AllocMem_(SizeOf.NrMessage, #MEMF_PUBLIC|#MEMF_CLEAR)
-
- ; Check if memory has been allocated
- If *nrmsg = 0
- NPrint "B: Not enough memory for message"
- End
- End If
-
- ; Try to find program A's message port
- *msgp = FindPort_("NrPort")
- If *msgp = 0
- NPrint "B: Could not find A's message port"
- Goto _end2
- End If
-
- ; Create a reply port. Note that you do not have to name it or give it
- ; a priority, as it will not be added to public port list
- *replymsgp = CreateMsgPort_
-
- ; Check if message port was created
- If *replymsgp = 0
- NPrint "B: Not enough memory to create reply port"
- Goto _end2
- End If
-
- ; Initialise the message, set type to NT_MESSAGE
- *nrmsg\SystemMsg\mn_Node\ln_Type = #NT_MESSAGE
-
- ; Give the message a pointer to our reply port
- *nrmsg\SystemMsg\mn_ReplyPort = *replymsgp
-
- ; Set the length of our message
- *nrmsg\SystemMsg\mn_Length = SizeOf.NrMessage
-
- ; Set the message number (data we wish to pass)
- *nrmsg\number = Rnd(32000)
-
- ; Inform the user
- NPrint "B: Everything is ready!"
- NPrint "B: Sending value: ",*nrmsg\number
-
- ; Send the message
- PutMsg_ *msgp, *nrmsg
-
- ; After we have sent our message, we cannot access or alter the message
- ; until we receive a reply from it
- NPrint "B: Message sent, waiting..."
-
- ; Wait at reply port. See prog A source for alternative method of waiting
- WaitPort_ *replymsgp
-
- ; Try to receive as many messages as possible. Note that we do not need
- ; to reply to messages here, because we created them, and this port is
- ; only used as a reply port
- *msg = GetMsg_(*replymsgp)
- While *msg
- ; We may now examine the message
- NPrint "B: We have received a reply"
- NPrint "B: Value received: ",*msg\number
- ; You may normally need to free the messages here, because you are probably
- ; finished with them when you receive the reply. But we only sent one, so
- ; we don't need to track any stuff.
- *msg = GetMsg_(*replymsgp)
- Wend
-
- DeleteMsgPort_ *replymsg
-
- _end2:
- ; If we have allocated memory for message, free it
- If *nrmsg Then FreeMem_ *nrmsg, SizeOf.NrMessage
-
- NPrint "The end"
- End
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-